package cn.yuanqiao.web.controller.archive.storeRoom;

import cn.yuanqiao.archive.storeRoom.domain.Box;
import cn.yuanqiao.archive.storeRoom.domain.OutBound;
import cn.yuanqiao.archive.storeRoom.domain.OutInLogs;
import cn.yuanqiao.archive.storeRoom.service.IInAndOutBoundService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

@RestController
@RequestMapping("/archive/inOut")
public class InAndOutBoundController extends BaseController {

    //列表
    @Autowired
    private IInAndOutBoundService inAndOutBoundService;

    @RequestMapping("/outList")
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:archiveOutbound:list')")
    public TableDataInfo outList(@RequestBody Box box){
        startPage();
        List<OutBound> list=inAndOutBoundService.outList(box);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:archiveStorage:list')")
    @GetMapping("/inList")
    public TableDataInfo InList( OutInLogs outInLogs) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        startPage();
        if(outInLogs.getEdCrkqr()!=null){
            outInLogs.setEdCrkqr(sdf1.parse(sdf.format(outInLogs.getEdCrkqr())+" 23:59:59"));
        }
        List<OutInLogs> list= inAndOutBoundService.getInList(outInLogs);
        return getDataTable(list);
    }

    @Log(title = "入库", businessType = BusinessType.INSERT)
    @PostMapping("/inBound")
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:archiveStorage:in')")
    public AjaxResult inBound(@RequestBody List<OutInLogs> list){
        boolean flage=inAndOutBoundService.inBound(list);
        if(flage){
            return AjaxResult.success();
        }else{
            return AjaxResult.error();

        }
    }
    @Log(title = "出库", businessType = BusinessType.INSERT)
    @PostMapping("/outBound")
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:archiveStorage:out')")
    public AjaxResult outBound(@RequestBody OutInLogs outInLogs) {
        boolean flage= inAndOutBoundService.outBound(outInLogs);
        if(flage){
            return AjaxResult.success();
        }else{
            return AjaxResult.error();

        }
    }

}
